css style: Accumulate changes in place
authorMatthias Clasen <mclasen@redhat.com>
Mon, 28 Sep 2015 05:43:03 +0000 (01:43 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 28 Sep 2015 10:29:51 +0000 (06:29 -0400)
This avoids allocating a temporary bitmask, and lets us
avoid some value comparisons altogether.

gtk/gtkcssstyle.c
gtk/gtkcssstyleprivate.h
gtk/gtkcsswidgetnode.c

index c4afe134686faf14854437dcdfd951ca8f5b076d..d577dc79d3bf191251b2f50aacd7d86ae63b5623 100644 (file)
@@ -83,25 +83,27 @@ gtk_css_style_get_section (GtkCssStyle *style,
 }
 
 GtkBitmask *
-gtk_css_style_get_difference (GtkCssStyle *style,
+gtk_css_style_add_difference (GtkBitmask  *accumulated,
+                              GtkCssStyle *style,
                               GtkCssStyle *other)
 {
-  GtkBitmask *result;
-  guint i, len;
+  gint len, i;
 
   if (style == other)
-    return _gtk_bitmask_new ();
+    return accumulated;
 
-  result = _gtk_bitmask_new ();
   len = _gtk_css_style_property_get_n_properties ();
   for (i = 0; i < len; i++)
     {
+      if (_gtk_bitmask_get (accumulated, i))
+        continue;
+
       if (!_gtk_css_value_equal (gtk_css_style_get_value (style, i),
                                  gtk_css_style_get_value (other, i)))
-        result = _gtk_bitmask_set (result, i, TRUE);
+        accumulated = _gtk_bitmask_set (accumulated, i, TRUE);
     }
 
-  return result;
+  return accumulated;
 }
 
 gboolean
index d3226a635a1ea60e10b7cef54a6fbb682957f828..ff0298082f3e41f3c2aaf0a9d960af7891d23399 100644 (file)
@@ -64,7 +64,8 @@ GtkCssValue *           gtk_css_style_get_value                 (GtkCssStyle
                                                                  guint                   id);
 GtkCssSection *         gtk_css_style_get_section               (GtkCssStyle            *style,
                                                                  guint                   id);
-GtkBitmask *            gtk_css_style_get_difference            (GtkCssStyle            *style,
+GtkBitmask *            gtk_css_style_add_difference            (GtkBitmask             *accumulated,
+                                                                 GtkCssStyle            *style,
                                                                  GtkCssStyle            *other);
 gboolean                gtk_css_style_is_static                 (GtkCssStyle            *style);
 
index cf68fb4e59bf3f87cd5e688d7b03d67f3f9b3d06..5e931017c7b6e272f12a58b837805c62239b7788 100644 (file)
@@ -50,7 +50,6 @@ gtk_css_widget_node_style_changed (GtkCssNode   *cssnode,
                                    GtkCssStyle  *new_style)
 {
   GtkCssWidgetNode *node;
-  GtkBitmask *diff;
 
   node = GTK_CSS_WIDGET_NODE (cssnode);
 
@@ -59,9 +58,7 @@ gtk_css_widget_node_style_changed (GtkCssNode   *cssnode,
 
   GTK_CSS_NODE_CLASS (gtk_css_widget_node_parent_class)->style_changed (cssnode, old_style, new_style);
 
-  diff = gtk_css_style_get_difference (new_style, old_style);
-  node->accumulated_changes = _gtk_bitmask_union (node->accumulated_changes, diff);
-  _gtk_bitmask_free (diff);
+  node->accumulated_changes = gtk_css_style_add_difference (node->accumulated_changes, new_style, old_style);
 }
 
 static gboolean
@@ -70,7 +67,7 @@ gtk_css_widget_node_queue_callback (GtkWidget     *widget,
                                     gpointer       user_data)
 {
   GtkCssNode *node = user_data;
-  
+
   gtk_css_node_invalidate_frame_clock (node, TRUE);
   _gtk_container_queue_restyle (GTK_CONTAINER (widget));